home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSVOLLBL.C < prev    next >
C/C++ Source or Header  |  1993-05-31  |  3KB  |  114 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bsvollbl.c
  5. //   Title:    Base Library
  6. //  Notice:    Copyright (c) 1991-1993, John Weeder, All Rights Reserved.
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains to read the volume label of a drive. This code is only
  25. //    valid under DOS or OS/2.
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <bs.h>
  46.  
  47. //----------------------------------------------------------------------------
  48. //   Description:    Get volume label.
  49. //    Parameters:    sDrive    Drive. 1=A, 2=B,...
  50. //                        psz        Buffer for volume label. Should be at least 14 
  51. //                                    bytes in size.
  52. //       Returns:    TRUE if successful.
  53. //----------------------------------------------------------------------------
  54. BOOL FN_E VolumeLabel(SHORT sDrive, PSZ psz)
  55. {
  56. #if OS_DOS || OS_OS2 || OS_WINDOWS || OS_PM
  57.  
  58.     struct find_t ff;
  59.     SHORT sOldDrive = DriveGet();
  60.  
  61.     Assert(psz);
  62.     psz[0] = '\0';
  63.     if (!DriveSet(sDrive))
  64.         return FALSE;
  65.  
  66.     CritErrReset();
  67.  
  68.    if (_dos_findfirst("\\*.*", _A_VOLID, &ff) == 0 && !CritErr())
  69.         {
  70.       if (strlen(ff.name) > 8)            
  71.          strcpy(&ff.name[8], &ff.name[9]);
  72.  
  73.         strcpy(psz, ff.name);
  74.         return DriveSet(sOldDrive);
  75.         }
  76.     DriveSet(sOldDrive);
  77.     return FALSE;
  78.  
  79. #else
  80.  
  81.     NOTUSED(sDrive);
  82.     Assert(psz);
  83.     psz[0] = '\0';
  84.     return TRUE;
  85.  
  86. #endif
  87. }
  88.  
  89.  
  90. //----------------------------------------------------------------------------
  91. //   Description:    Run standard test suite
  92. //    Parameters:    sTest        Test to run.
  93. //                                        0        Run all default tests (except).
  94. //       Returns:    TRUE if successful.
  95. //----------------------------------------------------------------------------
  96. #if COMPILE_TEST
  97. BOOL FN VolLblTest(SHORT sTest)
  98. {
  99.     CHAR szVolume[14];
  100.     SHORT i;
  101.  
  102.     NOTUSED(sTest);
  103.     for (i = 'A'; i <= 'Z'; ++i)
  104.         {
  105.         if (VolumeLabel(i,szVolume))
  106.             Output("Volume label of drive %c: is [%s]\n", i, szVolume);
  107.         }
  108.     return TRUE;
  109. }
  110. #endif
  111. //----------------------------------------------------------------------------
  112. //------------------------------- End of File --------------------------------
  113. //----------------------------------------------------------------------------
  114.